﻿using Avalonia.VisualTree;

namespace KinonekoSoftware.Foundation.UI.Controls
{
    public static class Xaml
    {
        public static T GetParent<T>(Visual dp, int maxDepth = 32) where T : Visual
        {
            var parent = dp.GetVisualParent();
            var depth  = 0;
            
            while (parent is not T && depth < maxDepth)
            {
                parent = parent?.GetVisualParent();
                depth++;
            }


            return parent as T;
        }
        
    }
}